﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace BYManageInfoSystem
{
    public partial class Frm_InternationalTradeBank : DockContent
    {
        private readonly DGBY.BLL.InternationalTradeBankTab m_billInternationalTradeBankTab = new DGBY.BLL.InternationalTradeBankTab();
        private int m_nSelectInternationalTradeBankID = 0;
        public Frm_InternationalTradeBank()
        {
            InitializeComponent();
        }

        private void Frm_InternationalTradeBank_Load(object sender, EventArgs e)
        {

        }

        private void ShowAllRecordInDataGridView()
        {
            dataGridViewInterTradeBankList.DataSource = null;
            DataSet m_ds = m_billInternationalTradeBankTab.GetAllList();
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                dataGridViewInterTradeBankList.DataSource = m_ds.Tables[0];
                dataGridViewInterTradeBankList.Columns[0].Visible = false;
            }
        }

        private void buttonShowAllRecordPort_Click(object sender, EventArgs e)
        {
            ShowAllRecordInDataGridView();
        }

        private void dataGridViewInterTradeBankList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridViewInterTradeBankList_Layout(object sender, LayoutEventArgs e)
        {

        }

        private void buttonAddPort_Click(object sender, EventArgs e)
        {
            DGBY.Model.InternationalTradeBankTab modelInternationalTradeBankTab = new DGBY.Model.InternationalTradeBankTab();
            modelInternationalTradeBankTab.InternationalTradeBankName = this.textBoxInternationalTradeBankName.Text;
            modelInternationalTradeBankTab.IsSpecialBank = this.checkBoxSpicelNotice.Checked;

            int nResult = m_billInternationalTradeBankTab.Add(modelInternationalTradeBankTab);

            if (nResult != 1)
            {
                Frm_Main.Log2DB(this.Text, "添加", modelInternationalTradeBankTab.InternationalTradeBankName);

                m_nSelectInternationalTradeBankID = m_billInternationalTradeBankTab.GetMaxId() - 1;
                ShowAllRecordInDataGridView();
            }
        }

        private void dataGridViewInterTradeBankList_MouseClick(object sender, MouseEventArgs e)
        {

        }

        private void dataGridViewInterTradeBankList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            string strInterTradeBankID = this.dataGridViewInterTradeBankList.Rows[this.dataGridViewInterTradeBankList.CurrentCell.RowIndex].Cells[0].Value.ToString();
            m_nSelectInternationalTradeBankID = Convert.ToInt32(strInterTradeBankID, 10);

            cellclick();
        }

        private void cellclick()
        {
            DGBY.Model.InternationalTradeBankTab modelInternationalTradeBankTab = m_billInternationalTradeBankTab.GetModel(m_nSelectInternationalTradeBankID);
            if (modelInternationalTradeBankTab != null)
            {
                this.textBoxInternationalTradeBankName.Text = modelInternationalTradeBankTab.InternationalTradeBankName;
                this.checkBoxSpicelNotice.Checked = modelInternationalTradeBankTab.IsSpecialBank;
            }
            else
            {
                this.textBoxInternationalTradeBankName.Text = "";
            }
        }

        private void buttonModifyPort_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_billInternationalTradeBankTab.GetModel(m_nSelectInternationalTradeBankID) == null)
                {
                    MessageBox.Show("数据库不存在该条记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                DGBY.Model.InternationalTradeBankTab modelInternationalTradeBankTab = m_billInternationalTradeBankTab.GetModel(m_nSelectInternationalTradeBankID);
                modelInternationalTradeBankTab.InternationalTradeBankName = this.textBoxInternationalTradeBankName.Text;
                modelInternationalTradeBankTab.IsSpecialBank = this.checkBoxSpicelNotice.Checked;

                m_billInternationalTradeBankTab.Update(modelInternationalTradeBankTab);

                Frm_Main.Log2DB(this.Text, "修改", modelInternationalTradeBankTab.InternationalTradeBankName);

                ShowAllRecordInDataGridView();
                MessageBox.Show("数据更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
    }
}
